package cn.big.bigd.ybp.model;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author fan
 *
 */
@Entity
public class YbpRole implements GrantedAuthority {

    private static final long serialVersionUID = 5635641430953788465L;

    // Predefiend User roles
    public static final YbpRole ADMIN = new YbpRole(1, "ADMIN");
    
    public static final YbpRole USER = new YbpRole(2, "USER");

    public static final YbpRole SUPERADMIN = new YbpRole(3, "SUPERADMIN");
    

    @Id
    Integer id;

    String role;

    @ManyToMany(mappedBy = "ybpRoleList")
    List<YbpUser> ybpUserList = new ArrayList<YbpUser>();

    public YbpRole(){}

    public YbpRole(int id, String role) {
        this.id = id;
        Assert.hasText(role, "A granted authority textual representation is required");
        this.role = role;
    }

    @Override
    public String getAuthority() {
        return role;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public List<YbpUser> getUserList() {
        return ybpUserList;
    }

    public void setUserList(List<YbpUser> ybpUserList) {
        this.ybpUserList = ybpUserList;
    }

    public String toString() {
        return this.role;
    }
}
